package com.manage.web.controller;

import com.manage.model.vo.Result;
import com.manage.model.po.Staff;
import com.manage.model.dto.StaffDTO;
import com.manage.service.StaffService;
import com.manage.web.data.CreateTestData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 员工操作接口
 * @author duaiyu
 * @version V1.0
 * @date 2022/2/20
 * 来源：自研
 */
@Slf4j
@Controller
@RequestMapping(value = "/staffController")
public class StaffController {
    public static AtomicInteger id = new AtomicInteger(0);
    public static AtomicInteger ac = new AtomicInteger(0);
    Integer count = 0;
    @Resource
    StaffService staffService;
    /** 查询员工 */
    @ResponseBody
    @RequestMapping(value = "/queryStaff", method = RequestMethod.GET)
    public List<Staff> queryStaff(){
        return staffService.queryStaff();
    }

    /** 导出excel */
    @ResponseBody
    @RequestMapping(value = "/exportStaff", method = RequestMethod.GET)
    public String exportStaff(){
        return staffService.exportStaff();
    }

    /** 复杂表头的导出 */
    @ResponseBody
    @RequestMapping(value = "/exportComplexStaff", method = RequestMethod.GET)
    public String exportComplexStaff(){
        return staffService.exportComplexStaff();
    }

    /** 添加测试数据 */
    @ResponseBody
    @RequestMapping(value = "/addStaff", method = RequestMethod.GET)
    public Result addStaff(){
        List<StaffDTO> staffs = null;
        while(count <= 5000000){
            staffs = CreateTestData.createStaffTestData(id, ac);
            for (StaffDTO staff : staffs){
                staffService.addStaff(staff);
                System.out.println("staff= [ " + staff + " ]");
            }
            count += staffs.size();
            id.set(count);
            ac.set(count);
        }
        System.out.println("count=" + count);
        return Result.succee(1);
    }
}
